<?php
/**
 * 工单催签申请
 * User: Administrator
 * Date: 2018/8/6/006
 * Time: 22:56
 */

namespace app\lib\Order\OrderOption;
use app\lib\Order\IsOrder\IsOrder;
use app\lib\Order\OrderExtensionConfig\GetOrderBindingExtension;
use app\lib\Order\OrderPaymentNotice\AddOrderNotice;
use app\lib\Order\OrderPaymentNotice\OrderNotice;

class OrderUrgeSignOption
{
    protected $orderId;
    protected $opUid;
    protected $content;
    public function __construct($orderId,$opUid,$content)
    {
        $this->orderId = $orderId;
        $this->opUid   = $opUid;
        $this->content  = $content;
    }

    /**
     * 验证
     * @throws \Exception
     */
    protected function check(){
        /*是否工单进行中*/
        if((new IsOrder($this->orderId))->isExecuteOrder()){
            exception('该工单状态异常无法申请');
        }
        if((new OrderNotice($this->orderId))->isNoReviewSign()){
            exception('该工单已经申请了催签操作，请等待审核');
        }
        /*是否绑定了待签收标签*/
        if((new GetOrderBindingExtension($this->orderId))->isOrderBindingSign()){
            exception('该工单已绑定了待交款标签');
        }
        if(empty($this->content)){
            exception('签收内容不能为空');
        }
        return true;
    }

    /**
     * 签收申请执行代码
     * @return bool
     * @throws \Exception
     */
    public function save(){
        $this->check();
        $noticeModel = new AddOrderNotice();
        /*写入通知申请*/
        $noticeModel->setOpUid($this->opUid)->setOrderId($this->orderId)
            ->setContent('催签收,工单id为['.$this->orderId.']要请雇主签收,签收内容:'.$this->content)
            ->SignOrderNotice();
        return true;
    }





}